package LeetCode;

public class LC24 {
    public ListNode swapPairs(ListNode head) {
        if(head==null || head.next==null) {
            return head;
        }
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode p = dummy, q = p.next;
        while (q !=null &&q.next != null){
            ListNode temp = q.next.next;
            p.next = q.next;
            q.next.next = q;
            q.next = temp;
            p = q;
            q = q.next;
        }
        return dummy.next;
    }
}
